﻿using System.Web.Mvc;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using CMS.Controllers;
using Castle.MicroKernel.Registration;

namespace CMS.Web
{
    /// <summary>
    /// class controller installer
    /// </summary>
    public class ControllerInstaller : IWindsorInstaller
    {
        /// <summary>
        /// Performs the installation in the <see cref="T:Castle.Windsor.IWindsorContainer"/>.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="store">The configuration store.</param>
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            //// Register all controller to IoC
            container.Register(AllTypes.FromThisAssembly()
                                .BasedOn<IController>()
                                .If(Component.IsInSameNamespaceAs<HomeController>())
                                .If(t => t.Name.EndsWith("Controller"))
                                .Configure(c => c.LifestyleTransient()));
        }
    }
}
